/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;
import DTO.CNhomKhachHang;
import DTO.CFields;
import DTO.CTon_Kho;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class CNhomKhachHangDAO extends IData<CNhomKhachHang>{
    public CNhomKhachHangDAO(){
    }

    @Override
    public CNhomKhachHang add(CNhomKhachHang item) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    

    @Override
    public void saveBatch() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int addrows(List<CNhomKhachHang> list, SubConfig config) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public CNhomKhachHang Find(CNhomKhachHang item, List<CNhomKhachHang> list) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    protected Object OnSubmit(CNhomKhachHang item, int t, SubConfig config) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Object insertOnSubmit(CNhomKhachHang item, SubConfig config) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Object updateOnSubmint(CNhomKhachHang item, SubConfig config) {
        String mysql ="update " + CFields.tb_nhom_khach_hang + " set "
                + CFields.chiet_khau + "=?," + CFields.ten + "=? where " + CFields.id + " =?";
        Object result = 0;
        try {
            PreparedStatement cs = config.connec.prepareStatement(mysql);
            cs.setInt(1, item.getChietKhau());
            cs.setString(2, item.getTen());
            cs.setLong(3, item.getId());
            result = cs.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(CNhomKhachHangDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }

    @Override
    public Object deleteOnSubmint(CNhomKhachHang item, SubConfig config) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    protected CNhomKhachHang getItem(ResultSet rs) {
        CNhomKhachHang item = new CNhomKhachHang();
        try {
            item.setId(rs.getLong(CFields.id));
            item.setTen(rs.getString(CFields.ten));
            item.setChietKhau(rs.getInt(CFields.chiet_khau));
        } catch (SQLException ex) {
            Logger.getLogger(CNhomKhachHangDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return item;
    }

    @Override
    public List<CNhomKhachHang> getAll(SubConfig config) {
        String mysql ="select * from " + CFields.tb_nhom_khach_hang + " order by id asc ";        
        return this.getAll(mysql, config);
    }
    @Override
    protected void add(CNhomKhachHang item, int t) {
        try {
            ps.setInt(1, item.getChietKhau());
            ps.setLong(2, item.getId());
            ps.addBatch();
        } catch (SQLException ex) {
            Logger.getLogger(CNhomKhachHangDAO.class.getName()).log(Level.SEVERE, null, ex);
        }        
    }
    
    public void updates(List<CNhomKhachHang> list,SubConfig config){
        this.query = "update " + CFields.tb_nhom_khach_hang + " set " 
                + CFields.chiet_khau + "=? where " + CFields.id + "=?";
        try {
            this.updateRows(list, config);
        } catch (SQLException ex) {
            Logger.getLogger(CNhomKhachHangDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
